<template>
	<view class="order">
		<view class="navbar">
			<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{ current: tabIndex === index }" @click="tabIndex = index">{{ item.text }}</view>
		</view>
		<!-- <view class="center"> -->
		<swiper :current="tabIndex" class="swiper-box" duration="300" @change="changeTab">
			<swiper-item class="tab-content" v-for="(item, index) in navList" :key="index">
				<!-- <view class="swiper-item"> -->
				<scroll-view class="list-scroll-content" :scroll-y="true" @scrolltolower="scrolltolower">
					<!-- <view style="height: 112upx;"></view> -->
					<view class="consume-item" v-for="(item, index) in creditList" :key="index" v-if="tabIndex == 0">
						<view class="consume-left">
							<view class="num">{{ item.remark }}</view>
							<view class="time">{{ item.create_at }}</view>
						</view>
						<view class="money">{{ item.num }}</view>
					</view>
					<view class="consume-item" v-for="(item, index) in listData" :key="index" v-if="tabIndex == 1">
						<view class="consume-left">
							<view class="num">{{ item.log }}</view>
							<view class="time">{{ item.time }}</view>
						</view>
						<view class="money">+{{ item.credit }}</view>
					</view>
					<view class="not-data" v-if="creditList.length == 0 && tabIndex == 0">暂无数据</view>
					<view class="not-data" v-if="listData.length == 0 && tabIndex == 1">暂无数据</view>
				</scroll-view>
				<!-- </view> -->
			</swiper-item>
		</swiper>
		<!-- </view> -->
		<!--  -->
		<view class="mask" v-if="isMask">
			<view class="mask_top"></view>
			<view class="mask_content">
				<!-- 标题 -->
				<view class="title"><text>请选择取消订单原因</text></view>
				<!-- 选择项 -->
				<view class="options">
					<radio-group @change="_returnReason">
						<view class="list" v-for="(item, index) in reasonList" :key="index">
							<text class="common_text_style">{{ item.title }}</text>
							<radio :value="item.state" color="#f81149" style="transform: scale(0.7);"></radio>
						</view>
					</radio-group>
					<!-- 确认按钮 -->
					<view class="btn">
						<view class="confirm" @tap="maskShow(false)">取消</view>
						<view class="confirm confirm-btn" @tap="handleCancelOrder">确定</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import service from '@/store/service.js';
export default {
	data() {
		return {
			tabIndex: 0,
			cancelOrder: false,
			isMask: false, //遮罩
			creditList: [],
			listData: [],
			returnReason: '',
			id: '',
			myAddress: '',
			page: 1,
			lastPage: 0,
			limit: 10,
			navList: [
				// {
				// 	text: '全部',
				// 	state: 'all'
				// },
				{
					text: '消费明细',
					state: '0'
				},
				{
					text: '签到明细',
					state: '1'
				}
				// {
				// 	text: '未中标',
				// 	state: '3'
				// },
				// {
				// 	text: '待发货',
				// 	state: '2'
				// },
				// {
				// 	text: '待收货',
				// 	state: '4'
				// }
			],
			reasonList: [
				{
					title: '我不想买了',
					state: '1'
				},
				{
					title: '信息填写错误，重拍',
					state: '2'
				},
				{
					title: '卖家缺货',
					state: '3'
				},
				{
					title: '同城见面交易',
					state: '4'
				},
				{
					title: '其他原因',
					state: '0'
				}
			]
		};
	},
	onLoad(option) {
		this.$nextTick(function() {
			if (option.id) {
				this.tabIndex = option.id;
			}
		});
		this.getList(1);
	},
	onShow: function() {},
	onNavigationBarButtonTap(e) {
		// console.log('编辑');
		// this.check = !this.check;
		uni.navigateTo({
			url: './myGroup'
		});
	},
	onReachBottom() {
		// this.getTeams();
	},
	methods: {
		scrolltolower(e) {
			console.log('滚动到底部==>>', e);
			let that = this;
			if (that.page < that.lastPage) {
				that.page = that.page + 1;
				that.getList(2);
			} else {
				that.$api.msg('没有更多数据了~');
			}
		},
		handleConfirm(id) {
			console.log(id);
		},
		editAddress(address, num, pid) {
			uni.setStorageSync('myAddress', address);
			uni.navigateTo({
				url: `/pages/order/addAddress?num=${num}&pid=${pid}`
			});
		},
		jump(url, id) {
			uni.navigateTo({
				url: url
			});
		},
		jumpUrl(url, id) {
			uni.switchTab({
				url: url
			});
		},
		//swiper 切换
		changeTab(e) {
			this.tabClick(e.target.current);
		},
		tabClick(index) {
			// console.log(index, 777);
			this.page = 1;
			// uni.pageScrollTo({
			// 	scrollTop: 0, //距离页面顶部的距离
			// 	duration: 100
			// });
			this.tabIndex = index;
			this.getList(1);
		},
		//确定取消订单
		confirm() {
			this.isMask = !this.isMask;
		},
		// 遮罩
		maskShow(boolean) {
			// console.log(3453);
			this.isMask = false;
			if (boolean) {
			}
		},
		// 退货原因
		_returnReason(returnReason) {
			if (returnReason) {
				this.returnReason = returnReason.detail.value;
				// console.log(returnReason.detail.value, 233);
			}
		},
		getList(e) {
			var self = this;
			// console.log(self.tabIndex, 666);
			if (self.tabIndex == 0) {
				self.$http
					.post(service.api.balance.myCredit, {
						page: self.page,
						type: 1,
						paytype: 1
					})
					.then(function(res) {
						var list = res.data.data;
						if (e == 1) {
							self.creditList = list;
							// console.log(self.creditList.length, 444);
						} else if (e == 2) {
							self.creditList = self.creditList.concat(list);
						}
						self.lastPage = Math.ceil(res.data.total / res.data.psize);
					});
			} else {
				self.$http
					.get(service.api.user.signList, {
						page: self.page,
						pageSize: self.limit
					})
					.then(function(res) {
						// console.log(res,223)
						var list = res.data;
						if (e == 1) {
							self.listData = list;
							// console.log(self.listData.length, 444);
						} else if (e == 2) {
							self.listData = self.listData.concat(list);
						}
						self.lastPage = Math.ceil(res.data.total / res.data.psize);
					});
			}
		},
		cancel(id) {
			this.isMask = !this.isMask;
			this.id = id;
		},
		joinGroup(id) {
			uni.navigateTo({
				url: '../createOrder/orderDetail?orderid=' + id
			});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	height: 100%;

	.order {
		height: 100%;
		position: fixed;
		z-index: 100;
		width: 100%;
	}
}

.swiper-box {
	height: 100%;
	padding-top: 90upx;
	box-sizing: border-box;
	padding-bottom: 90upx;
}

uni-swiper-item {
	overflow: auto;
}

.navbar {
	width: 100%;
	display: flex;
	height: 40px;
	// padding: 0 5px;
	background: #f3f3f3;
	box-shadow: 0px 4upx 8upx #dcdfe6;
	position: fixed;
	// top: 88upx;
	z-index: 200;

	.nav-item {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100%;
		font-size: 15px;
		color: #303133;
		position: relative;

		&.current {
			color: #f81149;

			&:after {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 0;
				transform: translateX(-50%);
				width: 50px;
				height: 0;
				/* border-bottom: 2px solid #fa436a; */
				border-bottom: 4upx solid #f81149;
			}
		}
	}
}

.order-list {
	margin-top: 110upx;
}

.order-item {
	margin-bottom: 20upx;
	margin: 20upx;
	background-color: #fff;
	padding: 30upx 22upx 0 22upx;
	border-radius: 20upx;
}

.order-top {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.num {
	font-size: 26upx;
	color: #666666;
}

.state {
	color: #f81149;
	font-weight: bold;
}

.order-center {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.img {
	width: 190upx;
	margin-top: 30upx;
	margin-bottom: 24upx;
}

.order-img {
	width: 190upx;
	height: 187upx;
}

.center-right {
	flex: 1;
	margin-left: 25upx;
}

.title {
	color: #333;
	font-size: 26upx;
	font-weight: bold;
	margin-bottom: 20upx;
}

.detail {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.detail-price {
	color: #333;
	font-size: 32upx;
	font-weight: bold;
}

.detail-num {
	color: #333;
	font-size: 24upx;
	font-weight: bold;
}

.total {
	display: flex;
	justify-content: flex-end;
	color: #333;
	font-weight: bold;
	padding: 20upx 0;
}

.bottom {
	display: flex;
	justify-content: flex-end;
}

.money {
	color: #f81149;
	font-weight: bold;
}

.back {
	border: 1px solid #999;
	border-radius: 33upx;
	width: 186upx;
	height: 65upx;
	line-height: 65upx;
	text-align: center;
	box-sizing: border-box;
	color: #666;
	margin-right: 24upx;
}

.warn {
	border: 1px solid #f81149;
	border-radius: 33upx;
	width: 186upx;
	height: 65upx;
	line-height: 65upx;
	text-align: center;
	box-sizing: border-box;
	height: 65upx;
	color: #f81149;
}

.cancel-order {
	position: fixed;
	top: 0;
	left: 0;
	width: 100vw;
	height: 100vh;
	background: rgba(0, 0, 0, 0.63);
	z-index: 1000;

	.cause {
		width: 630upx;
		height: 761upx;
		background-color: #fff;
		border-radius: 12upx;
		position: absolute;
		left: 50%;
		top: 50%;
		margin-left: -315upx;
		margin-top: -380.5upx;

		.title {
			width: 100%;
			height: 105upx;
			line-height: 105upx;
			text-align: center;
			color: #333333;
			font-size: 32upx;
			font-weight: bold;
			border-bottom: 2upx solid rgba(241, 241, 241, 1);
		}

		.cause-box {
			display: flex;
			justify-content: space-between;
			padding: 23upx 22upx 23upx 38upx;
		}

		.btn {
			display: flex;
			padding: 60upx 0 40upx 0;

			.cancel {
				flex: 1;
				text-align: center;
				color: #333333;
				font-size: 32upx;
			}

			.confirm {
				flex: 1;
				text-align: center;
				color: #000000;
				font-size: 32upx;
			}
		}
	}
}

// 遮罩样式
.mask {
	position: fixed;
	top: 0;
	// right: 60upx;
	// left: 60upx;
	bottom: 0;
	height: 100%;
	width: 100%;
	display: flex;
	flex-direction: column;
	z-index: 99;

	.mask_top {
		opacity: 0.53;
		background: rgba(0, 0, 0, 1);
		flex: 1;
	}

	.mask_content {
		height: 800upx;
		margin: 0 60upx 300upx 60upx;
		// width: 100%;
		background-color: #ffffff;
		position: absolute;
		bottom: 0;
		right: 0;
		left: 0;
		background: rgba(255, 255, 255, 1);
		border-radius: 12upx;
		padding-top: 42upx;
		// box-sizing: border-box;

		.title {
			height: 105upx;
			width: 100%;
			display: flex;
			justify-content: center;
			// padding: 0 15upx 0 272upx;
			align-items: center;
			box-sizing: border-box;
			padding-bottom: 30upx;
			border-bottom: 1px solid #f1f1f1;

			> text {
				height: 34upx;
				font-size: 32upx;
				font-weight: bold;
				color: rgba(51, 51, 51, 1);
				line-height: 34upx;
			}

			> image {
				height: 58upx;
				width: 58upx;
			}
		}
	}
}

.options {
	margin-top: 10upx;

	.list {
		height: 100upx;
		width: 100%;
		padding: 0 30upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		color: #333;
		font-size: 32upx;
		// border-bottom: 1px solid rgba(244, 244, 244, 1);
	}

	.list_end {
		border-bottom: 0;
	}
}

.btn {
	display: flex;
	justify-content: space-between;
	align-items: center;
	// width: 710upx;
	height: 100upx;
	// background: linear-gradient(90deg, rgba(233, 144, 64, 1) 0%, rgba(255, 123, 76, 1) 100%);
	// border-radius: 10upx;
	font-size: 36upx;
	font-weight: 500;
	text-align: center;
	line-height: 100upx;
	// color: rgba(255, 255, 255, 1);
	margin: 25upx auto;
	color: #333;
	font-size: 32upx;

	.confirm {
		width: 50%;
		font-size: 32upx;
	}

	.confirm-btn {
		color: #000;
		font-weight: bold;
	}
}

.not-data {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 200upx;
}

.list-scroll-content {
	height: 100%;
}

.consume-item {
	background-color: #fff;
	padding: 28upx 22upx 22upx;
	border-bottom: 1px solid #f4f4f4;
	margin: 0 20upx;
	border-radius: 10upx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.consume-item:nth-last-child(1) {
	border-bottom: none;
}

.consume-left {
	display: flex;
	// justify-content: space-between;
	flex-direction: column;
	justify-content: space-around;
}

.num {
	color: #333;
	// width: 450upx;
}

.time {
	color: #666666;
	font-size: 24upx;
	font-weight: 500;
	// text-align: center;
}

.price {
	color: #333;
	font-weight: bold;
	display: flex;
	justify-content: flex-end;
}

.money {
	display: flex;
	flex-direction: column;
	// align-items: right;
	// justify-content: space-between;
	color: #f81149;
	// margin-top: 20upx;
}

.not-data {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 20upx;
}

uni-checkbox /deep/ .uni-checkbox-input {
	border-radius: 50%;
}

uni-checkbox /deep/ .uni-checkbox-input::before {
	content: '';
	width: 40upx;
	height: 40upx;
	border-radius: 50%;
	background-color: #f81149;
}

uni-checkbox:not([disabled]) /deep/ .uni-checkbox-input:hover {
	border-color: #f81149;
}
</style>
